home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 223_01 / itoo.c < prev    next >
Text File  |  1980-01-01  |  768b  |  23 lines

  1. /*
  2. ** itoo -- converts nbr to octal string of length sz
  3. **         right adjusted and blank filled, returns str
  4. **
  5. **        if sz > 0 terminate with null byte
  6. **        if sz = 0 find end of string
  7. **        if sz < 0 use last byte for data
  8. */
  9.    static int digit;
  10.  
  11. itoo(nbr, str, sz)  int nbr;  char str[];  int sz;  {
  12.   if(sz>0) str[--sz]=0;
  13.   else if(sz<0) sz = -sz;
  14.   else while(str[sz]!=0) ++sz;
  15.   while(sz) {
  16.     digit=nbr&7; nbr=(nbr>>3)&8191;
  17.     str[--sz]=digit+48;
  18.     if(nbr==0) break;
  19.     }
  20.   while(sz) str[--sz]=' ';
  21.   return str;
  22.   }
  23.